<?php
namespace app\services\index;

use app\services\RESTfulAPI;
use kernel\library\Es7;
use kernel\library\Config;

class Init extends RESTfulAPI
{
    protected function post(array $input = [])
    {
        return $this->get($input);
    }

    protected function get(array $input = [])
    {
        return $this->result([
            'homeInfo' => $this->getHomeInfo(),
            'logoInfo' => $this->logoInfo(),
            'menuInfo' => $this->getMenuInfo(),
        ]);
    }

    protected function delete(array $input = [])
    {}

    protected function put(array $input = [])
    {}

    
    protected function getHomeInfo(){
        return [
            "title" => "首页",
            "href" => "/admin/page/main.html"
        ];
    }
    
    protected function logoInfo(){
        return [
            "title" => "ESphp管理",
            "image" => "/admin/static/img/logo.png",
            "href" => ""
        ];
    }
    public function getMenuInfo(){
        //拿到所有的index
        $res = Es7::getInstance(Config::get('app.eshost'))->allIndex();
        
        $chind = [];
        foreach($res as $k => $v){
            $chind[] = [
                'id' => $v['index'],
                'title' => $v['index'],
                'icon' => 'fa fa-circle-o',
                'api' => 'admin/finder?_index='.$v['index'],
                'target' => '_self',
                'href' => '/admin/page/finder.html?api=/admin/finder/'.$v['index'],
            ];
        }
        return [
            [
                'id' => -1,
                'title' => "ES索引",
                'icon' => 'fa fa-circle-o',
                'api' => '',
                'target' => '_self',
                'href' => '',
                'child' => $chind
            ]
        ];;
    }
}

